﻿Imports VN.INS.DL.DH
Imports VN.INS.BL.BE
Imports VN.INS.Dominio
Public Class MantenimientoUnidadDA
    Public Function ListaUnidad(ByVal strNombre As String) As DataTable
        Dim objData As AdministradorOracle = New AdministradorOracle
        Dim objDt As DataTable
        Dim lxc_SQL As String
        Try
            lxc_SQL = "select unidad,descripcion from unidad  where upper(descripcion) like upper('" & strNombre & "%') order by descripcion"

            objDt = objData.ExecuteSQL(lxc_SQL, "Conexion.Oracle")
            Return objDt
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Public Function ListarUnidadesXNombre(ByVal strNombre As String) As List(Of Unidad) 'Adaptación para retornar entidades de dominio
        Dim objData As AdministradorOracle = New AdministradorOracle
        Dim objDt As DataTable
        Dim unidades As List(Of Unidad) = New List(Of Unidad)
        Dim unidad As Unidad
        Dim lxc_SQL As String
        Try
            lxc_SQL = "select unidad,descripcion from unidad  where upper(descripcion) like upper('" & strNombre & "%') order by descripcion"

            objDt = objData.ExecuteSQL(lxc_SQL, "Conexion.Oracle")

            For Each fila As DataRow In objDt.AsEnumerable
                unidad = New Unidad
                unidad.Codigo = CType(fila("unidad"), String)
                unidad.Nombre = CType(fila("descripcion"), String)
                unidades.Add(unidad)
            Next

            Return unidades
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Public Sub InsertarUnidad(ByVal unid As String, ByVal descr As String)
        Dim objData As AdministradorOracle = New AdministradorOracle
        Try
            objData.CreateInputOracle("unid", unid, 8)
            objData.CreateInputOracle("descr", descr, 300)

            objData.ExecuteOracle_NonQuery("insertarunidad", "Conexion.Oracle")
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
    Public Sub editarunidad(ByVal unid As String, ByVal descr As String)
        Dim objData As AdministradorOracle = New AdministradorOracle
        Try
            objData.CreateInputOracle("unid", unid, 8)
            objData.CreateInputOracle("descr", descr, 300)

            objData.ExecuteOracle_NonQuery("editarunidad", "Conexion.Oracle")
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
    Public Sub eliminarunidad(ByVal unid As String)
        Dim objData As AdministradorOracle = New AdministradorOracle
        Try
            objData.CreateInputOracle("unid", unid, 8)

            objData.ExecuteOracle_NonQuery("eliminarunidad", "Conexion.Oracle")
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
    Public Function Contarunidad(ByVal UNIDAD As String) As DataTable
        Dim objData As AdministradorOracle = New AdministradorOracle
        Dim objdt As DataTable
        Dim lxc_SQL As String
        Try
            lxc_SQL = "select sum(NUMERO) as NUMERO FROM (SELECT COUNT(PAF.UNIDAD) NUMERO FROM POA_ACTIVIDAD_FISICA PAF WHERE PAF.UNIDAD = '" & UNIDAD & "' " & _
                      "UNION " & _
                      "SELECT COUNT(P.UNIDAD) NUMERO FROM POA P WHERE '" & UNIDAD & "' IN (P.UNIDAD, P.UNIDAD2 ,P.UNIDAD3))"
            objdt = objData.ExecuteSQL(lxc_SQL, "Conexion.Oracle")
            Return objdt
        Catch ex As Exception
            Throw ex
        End Try
    End Function
End Class
